const express = require('express');
const path = require('path');

const app = express();

// 用来指定静态资源目录的
const middlewareFn = express.static(path.join(__dirname, './public'));

// 中间件（守卫）的挂载方法，所有的请求都会先经过这个挂载的中间件函数进行处理
//   如果匹配到相关的静态资源，那么就结束响应
app.use('/hehe', middlewareFn);
app.use('/dada', express.static('./files'));

// app.use(express.static('./files'));

const middlewareFn2 = (req, res, next) => {
  console.log('自定义的中间件函数执行了...');
  // 放行，继续向下传递
  // next();
  // res.send('hehe, 不让你过去。。。')
  next();
};

app.use(middlewareFn2);

app.get('/user', (req, res, next) => {
  console.log('/user 来了11111...');
  res.send('hehe...');
  next()
});

app.get('/user', (req, res, next) => {
  console.log('/user 222222...');
});

// app.post('/asdfasdf' ....)
// app.use('/aldsjflakjsdf'. ....)

app.listen(80, () => {
  console.log('app running at http://localhost');
});
